package org.jimmy.tang.lang;

/**
 * @author jimmy
 * 
 */
public class AbstractObject {
    public static void main(String[] args) {
        Person[] people = new Person[2];
        people[0] = new Employee3("Bod", 34, 5000);
        people[1] = new Student("Joun", 17, 6000);

        for (Person p : people) {
            System.out.print("Name:" + p.getName() + "\tAge:" + p.getAge()
                    + "\tDescription:" + p.getDescription() + "\t");
            if (p instanceof Employee3) {
                System.out.println(((Employee3) p).getFee());
            } else if (p instanceof Student) {
                System.out.println(((Student) p).getFee());
            }
        }
    }
}

abstract class Person {
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public abstract String getDescription();

    public final String getName() {
        return name;
    }

    public final void setName(String name) {
        this.name = name;
    }

    public final int getAge() {
        return age;
    }

    public final void setAge(int age) {
        this.age = age;
    }

    private String name;
    private int age;
}

class Employee3 extends Person {
    public Employee3(String name, int age, double fee) {
        super(name, age);
        id = nextId;
        nextId++;
        this.fee = fee;
    }

    // 定义Person抽象类的抽象方法
    @Override
    public String getDescription() {
        return "This is an employee. class name:" + this.getClass().getName();
    }

    // 定义访问器方法
    public double getFee() {
        return fee * 2;
    }

    public final int getId() {
        return id;
    }

    // 定义更改器方法
    public final void setFee(double salary) {
        fee = fee;
    }

    // 定义变量
    private double fee;
    private int id;
    private static int nextId = 1;
}

class Student extends Person {
    public Student(String name, int age, double fee) {
        super(name, age);
        this.fee = fee;
    }

    @Override
    public String getDescription() {
        return "This is a student. class name:" + this.getClass().getName();
    }

    public double getFee() {
        return fee;
    }

    public void setFee(double fee) {
        this.fee = fee;
    }

    private double fee;
}
